package org.demo.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;

@Component
@Slf4j
public class Scheduled {
    @Autowired
    private ThreadConfig threadConfig;

    public static int count = 1;

    @org.springframework.scheduling.annotation.Scheduled(cron = "*/10 * * * * *")
    public void cronjob() {
        log.info("第" + count++ + "次输出...");
        for (int i = 0; i < 2; i++) {
            threadConfig.executor().execute(this::write);
        }
    }

    public void write() {
        System.out.println("线程-" + Thread.currentThread().getId() + "在执行写入");
    }
}